package com.example.controller;


import com.example.pojo.Clazz;
import com.example.pojo.Result;
import com.example.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    //查询所有班级
    @GetMapping("/list")
    public Result findAll(){
        List<Clazz> all = clazzService.findAll();
        return Result.success(all);
    }

    //添加班级
    @PostMapping
    public Result save(@RequestBody Clazz clazz){
        clazzService.save(clazz);
        return Result.success();
    }
    //分页查询班级
    @GetMapping

    public Result findPage(@RequestParam(defaultValue = "1") Integer page,
                           @RequestParam(defaultValue = "5") Integer pageSize){
        return Result.success(clazzService.findPage(page,pageSize));
    }

    //删除班级

    @DeleteMapping("/{id}")

    public Result delete(@PathVariable Integer id){
        clazzService.delete(id);
        return Result.success();
    }
    //根据ID查询班级
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        return Result.success(clazzService.getById(id));
    }
    //修改班级
    @PutMapping

    public Result update(@RequestBody Clazz clazz){
        clazzService.update(clazz);
        return Result.success();
    }

}
